# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=scikit-image
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.19.3
pkgrel=2
pkgdesc='Image processing routines for SciPy (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
url="https://scikit-image.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-matplotlib>3.0.0"
"${MINGW_PACKAGE_PREFIX}-python-scipy>=1.0.1"
"${MINGW_PACKAGE_PREFIX}-python-pywavelets>=1.1.1"
"${MINGW_PACKAGE_PREFIX}-python-numpy>1.18.0"
"${MINGW_PACKAGE_PREFIX}-python-networkx>=2.0"
"${MINGW_PACKAGE_PREFIX}-python-imageio>=2.3.0"
"${MINGW_PACKAGE_PREFIX}-python-tifffile>=2019.7.26"
"${MINGW_PACKAGE_PREFIX}-python-pillow>7.1.1")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-pythran"
  "${MINGW_PACKAGE_PREFIX}-cython"
  "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest>=5.2.0"
"${MINGW_PACKAGE_PREFIX}-python-pytest-cov>=2.7.0"
"${MINGW_PACKAGE_PREFIX}-python-pytest-flake8"
"${MINGW_PACKAGE_PREFIX}-python-pytest-localserver"
"${MINGW_PACKAGE_PREFIX}-python-pooch")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: for imshow(x, fancy=True) and skivi"
"${MINGW_PACKAGE_PREFIX}-freeimage: for reading various types of image file formats"
"${MINGW_PACKAGE_PREFIX}-python-pyamg: fast cg_mg mode of random walker segmentation")
options=('!emptydirs')
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('24b5367de1762da6ee126dd8f30cc4e7efda474e0d7d70685433f0e3aa2ec450')

prepare() {
  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build_ext --inplace
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README.md"
}
